home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / comm / tlx_sq15.zip / JOINCONF.SLT < prev    next >
Text File  |  1990-12-20  |  10KB  |  295 lines

  1. //-----------------------------------------------------------
  2. // JOINCONF.SLT Join Conference.
  3. //
  4. // Note: Lines commented out with //!! are not used in this script,
  5. // but in other, related ones. Please don't delete them; they may
  6. // become useful later.
  7. //-----------------------------------------------------------
  8. // Author: Inge Vabekk
  9. //         Hamangskogen 108
  10. //         N-1300 SANDVIKA
  11. //         NORWAY
  12.  
  13. str bbs_type  [32]           // BBS type.
  14.    ,PrevConf  [20]=""        // Previous conference.
  15.    ,NextConf  [20]=""        // Next conference.
  16.    ,command   [10]           // Command prompt.
  17.    ,temp      [4]            // Temporary for short strings.
  18.                              // For the Global storage:
  19.    ,global   []="GLOBAL"     // Global script.
  20.    ,bbstype  []="BTYPE"      // BBS type.
  21.    ,conf     []="CONF"       // Current conference
  22.    ,prompt   []="PROMPT"     // Current command prompt.
  23.    ;     
  24.  
  25. int tol = 200                            // No activity for 20 sec.
  26.    ,stat, tmark                          // makes script time out. 
  27.    ,mbbs, pcb, rbbs, opus, fido, crcs 
  28.    ,PCBver                               // PCBoard version.
  29.    ;
  30.  
  31. //-----------------------------------------------------------   
  32. // Script starts here.
  33. //-----------------------------------------------------------   
  34.  
  35. main (str NewConf)
  36. {
  37. int c, i, j, ercnt, switched
  38.    ,yes, ent, par, con, com, co, y;
  39. str Sline [80]
  40.    ,pre    [4]
  41.    ,post   [4]
  42.    ,end    [4]
  43.    ,ans    [4]
  44.    ;
  45.  
  46.    NextConf = NewConf;                   // Use local, since it may
  47.                                          // be changed.
  48. // Only if online.
  49.  
  50.   if (!carrier())  
  51.   { failtone();
  52.     status_wind ("THIS SCRIPT ONLY WORKS IF YOU'RE ONLINE!",20);
  53.     return (-1);
  54.   }
  55.  
  56.   read (bbstype,bbs_type);               // Get BBS type. 
  57.   read (conf,PrevConf);                  // Get previous conference.
  58.   read (prompt,command);                 // Get command prompt.
  59.  
  60.   mbbs = pcb = rbbs = opus = fido = crcs = 0;
  61.   if      (bbs_type == "MBBS") mbbs = 1;
  62.   else if (bbs_type == "PCB")   pcb = 1;
  63.   else if (bbs_type == "RBBS") rbbs = 1;
  64.   else if (bbs_type == "OPUS") opus = 1;
  65.   else if (bbs_type == "FIDO") fido = 1;
  66.   else if (bbs_type == "CRCS") crcs = 1;
  67.   else                                          
  68.   { wrongBBS();                          // Don't know how to do it!
  69.     return (-1);
  70.   }
  71.  
  72.   if (mbbs)
  73.   { pre  = "(";                          // Define the delimiters
  74.     post = ")";                          // for the conference
  75.     end = "Q^M";                         // name.
  76.   }
  77.   else if (pcb)
  78.   { pre  = "t) ";
  79.     post = " (";
  80.     end = "^M";
  81.   }
  82.   else if (rbbs)
  83.   { pre  = "";
  84.     post = " Co";   
  85.     end = "^M";
  86.   }
  87.   co = strlen(pre);                      // Length of prefix.
  88.  
  89.   y=gety();
  90.   if (rbbs)
  91.   { --y;                                 // RBBS:
  92.     if (y<0) y=0;                        // Conf. name on previous line.
  93.   }
  94.   vgetchrs(0,y,Sline,0,80);              // Get command line from screen.
  95.  
  96.   if (pcb)                               // PCBoard: Do some extra checks
  97.   { if (strposi(PrevConf,"Main",0)==0    // for Main Board.
  98.      || strposi(Sline,"Main Boa",0) > 0)
  99.     { PrevConf = "Main Board";           // Set Main Board.
  100.       write (conf,PrevConf);
  101.     }
  102.   }
  103.  
  104.   if (strlen(PrevConf) < 1) do           // Have to find which conference
  105.   { j = -1;
  106.     if (rbbs)                            // RBBS: Conference name
  107.       i = 0;                             // at beginning of line.
  108.     else
  109.     { i = strposi(Sline,pre,0);          // Find start byte.
  110.       if (i < 0)
  111.       { i = strposi(Sline,"[",0);        // Not found: Try "[".
  112.         if (i >= 0)                      // Is this the old format?
  113.         { co = 1;                        // Yepp.
  114.           pre  = "[";                    // Starts with a left bracket,
  115.           post = "]";                    // ends with a right bracket.
  116.         }
  117.         i = i+co;                        // Proceed to conference name.
  118.       }
  119.     }
  120.     j = strposi (Sline,post,i);          // Find end byte.
  121.  
  122.     j = j-i;                             // Find the length.
  123.     if (j>0) 
  124.       substr (Sline,i,j,PrevConf);       // Conference found!
  125.     else
  126.       cputs (end);                       // Not found: Back to Main.
  127.     flush();
  128.   } while (j < 1);
  129.  
  130. // Previous conference known.
  131.  
  132.   for (i=0; subchr(NextConf,i)==' ';++i) // Find first non-space.
  133.     ;                                    // Find end of line.
  134.   for (j=strlen(NextConf)-1; subchr(NextConf,j)==' ' ;--j)
  135.     setchr(NextConf,j,0);                // Trim spaces from end of line.
  136.   if (i > 0)                             // Move it down to the 
  137.     subchrs (NextConf,i,j,NextConf);     // beginning of the line.
  138.  
  139.   ercnt = switched = 0;
  140.   if (pcb)
  141.   { if (strposi(NextConf,"Main",0) >= 0)
  142.       NextConf = "Main Board";           // Only one legal name
  143.     if (strposi(PrevConf,"Main",0) >= 0) // for Main Board.
  144.       PrevConf = "Main Board";
  145.   }
  146.   if (strposi(PrevConf,NextConf,0)==0)   // Same conference?
  147.     return (0);
  148.  
  149.   while (!switched && ercnt < 3)         // Until conference changed:
  150.   { ++ercnt;
  151.     flush();                             // Eat all input, then
  152.     if (pcb && strposi(NextConf,"Main Board",0)==0)
  153.       cputs("A");                        // Abandon Main Board.
  154.     else
  155.     { cputs("J ");                       // join the conference.
  156.       cputs(NextConf);
  157.     }
  158.  
  159.     ans = "";                            // Next answer.
  160.     con = track(NextConf,1);             // Check conference name.
  161.     if (pcb)
  162.     { ent = track("(Enter)=",0);
  163.       par = track("left)",0);            // ...minutes left
  164.       com = track(command,0);
  165.     }
  166.     else
  167.     { par = ent = -948;                  // Not used for MBBS.
  168.       if (mbbs)
  169.         com = track(command,0);
  170.       else if (rbbs)
  171.       { com = track("V,W,X>?",0);
  172.         ans = "n^M";                    // Browse conference without
  173.         ent = track("Y,[N])?",0);       // permanently joining (Y,[N])?
  174.         switched = 1;
  175.       }
  176.     }
  177.   
  178.     cputs("^M");
  179.     tmark = timer_start (tol);           // Just 20 sec. time-out.
  180.  
  181.     while ((stat=trig()) > 0)            // Wait for Command.
  182.     { if (stat == ent)
  183.       { if (pcb)                         // PCBoard:
  184.         { terminal();
  185.           y=gety();
  186.           vgetchrs(0,y,Sline,0,80);      // Get command line from screen.
  187.           if (strpos (Sline,"Mail Com") >=0)
  188.             ans = "qu^M";  // .... Main Board (0) Mail Command: (Enter)='xx...
  189.           else
  190.             ans = "n^M";                 // Scan since last read?
  191.         }                                // Scan for personal mail?
  192.         cputs (ans);                     // Send answer.
  193.       }
  194.       else if (stat == par)              // (Quit from mail command)
  195.         ++ercnt;                         // ...minutes left)
  196.  
  197.       else if (stat == com)              // Command:
  198.       { if (switched)                    // Check switch. If non-zero
  199.           write (conf,NextConf);         // we're in this conference.
  200.         break;
  201.       }
  202.       else if (stat == con)              // Conference name?
  203.         switched = 1;                    // We've switched.
  204.     }
  205.  
  206.     track_free(0);                       // Stop all tracking.
  207.   }                                      // Loops if unsuccesful.
  208.  
  209.   timer_free(0);
  210.   if (!switched)
  211.   { failtone();
  212.     prints ("JOIN CONFERENCE FAILED!");
  213.   }
  214.   if (!carrier()) switched = -1;
  215.   return (switched);
  216. }
  217.  
  218. //-----------------------------------------------------------
  219. // Wrong BBS type.
  220. //-----------------------------------------------------------
  221.  
  222. wrongBBS()
  223. {
  224. str help[32];
  225.  
  226.     failtone();                          // Alarm.    
  227.     help = "Illegal BBS type (or not found): ";
  228.     strcat (help,bbs_type);
  229.     strcat (help,"!");
  230.     status_wind (help,20);               // Display message for 2 sec.
  231. }
  232.  
  233. //-----------------------------------------------------------
  234. // Flush incomi